#pragma once

#ifdef __QT5_TARGET

#include <QtCore/QDate>
#include <QtCore/QDateTime>
#include <QtCore/QHash>
#include <QtCore/QList>
#include <QtCore/QMap>
#include <QtCore/QPair>

#else

#include <QMap>
#include <QDate>
#include <QDateTime>
#include <QList>
#include <QPair>
#include <QHash>

#endif

#include "korlapadmin_model_global.h"
#include "Schedule.h"
#include "Patient.h"
#include "VisitManager.h"
#include "Utils.hpp"
#include <algorithm>
#include "NullPointerException.h"
class KORLAPADMIN_MODEL_EXPORT ScheduleManager
{
public:
	ScheduleManager(void);
	~ScheduleManager(void);
	
	void deleteSchedule(Schedule* s);
	void updateSchedule(Schedule* s, const QString& note);
	void addSchedule(Schedule* schedule);
	QList<Schedule*> getSchedulesForThisWeek();
	QMap<QDateTime*,Schedule*>* getScheduleMapForThisWeek();
	Schedule* getSchedule(QDateTime date);
	Schedule* getSchedule(unsigned int sched_id);
	QList<Schedule*> getSchedules(Patient* p);
	QList<Schedule*> getAllSchedules();
	Schedule* getNextSchedule();
	Schedule* getLastSchedule();
	QPair<QDateTime*,QDateTime*>* getCurrentWeek();
	void setThisWeek(QPair<QDateTime*,QDateTime*>* dates);
	QPair<QDateTime*,QDateTime*>* getThisWeek();
	QPair<QDateTime*,QDateTime*>* getWeek(QDateTime dt);
	bool thisWeekLoaded();
	QList<QDateTime*>* getThisWeekDates();
	void addToThisWeekDates(QDateTime* date);
	Schedule* getScheduleByTime(unsigned int time);
	
private:
	QHash<unsigned int, Schedule*>* schedulesById;
	QMap<int, Schedule*>*		schedulesByTimeStamp;
	QMap<QDateTime*,Schedule*>* schedules;
	QMap<QDateTime*,Schedule*>* currentWeekCache;
	QMap<QDateTime*,Schedule*>* nextWeekCache;
	QMap<QDateTime*,Schedule*>* lastWeekCache;
	QList<QDateTime*>* thisWeekDates;
	QList<QDateTime*>* nextWeekDates;
	QList<QDateTime*>* lastWeekDates;
	QPair<QDateTime*,QDateTime*>* thisWeek;
	QPair<QDateTime*,QDateTime*>* nextWeek;
	QPair<QDateTime*,QDateTime*>* lastWeek;
};
